package se.webbzon.oschi01.worldcamera;

import java.awt.Dimension;

import javax.media.j3d.BranchGroup;
import javax.media.j3d.J3DGraphics2D;

import se.webbzon.oschi01.j3d.ExtendedCanvas3D;
import se.webbzon.oschi01.worldarea.WorldAppearance3D;

import com.sun.j3d.utils.universe.SimpleUniverse;

@Deprecated
public class DefaultWorldView extends ExtendedCanvas3D implements WorldView {
	
	// Auto generated serial version UID
	private static final long serialVersionUID = 4694725449512295410L;

	// The available properties of the WorldView
	public static final int	TRANSPARENCY	= (1<<0);
	
	// The camera components of this world view
	private final WorldCamera camera;
	private final WorldCameraHud hud;
	private final WorldCameraBackground background;
	
	// The 2D-graphics objects used in preRender and postRender
	private final J3DGraphics2D g3d;
	
	// The branch group of this view
	private final BranchGroup branchGroup;
	
	private WorldAppearance3D world;
	
	/*============================================================
	Constructors
	============================================================*/

	/** Creates a new abstract WorldAreaView. **/
	public DefaultWorldView(int viewProperties, Dimension d) {
		super(SimpleUniverse.getPreferredConfiguration());
		/*if (isSet(viewProperties,TRANSPARENCY))
			camera = new WorldCamera(WorldCamera.TRANSPARENCY,this);
		else
			camera = new WorldCamera(this);*/
		camera = null;
		hud = new WorldCameraHud(this,d);
		background = new WorldCameraBackground(this,d,false);
		
		// Create the 3D canvas
		setPreferredSize(new Dimension((int) d.getWidth(),(int) d.getHeight()));
		g3d = getGraphics2D();
		
		// Create the Java3D view structure
		branchGroup = new BranchGroup();
		
		// Add sub groups to branch group
		//branchGroup.addChild(camera.getNode());
		branchGroup.compile();
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	/*@Override public BranchGroup getJ3dBranch() {
		return branchGroup;
	}*/
	
	@Override public final WorldCamera getCamera() {
		return camera;
	}
	
	@Override public final WorldCameraPane getCameraHud() {
		return hud;
	}
	
	@Override public final WorldCameraPane getCameraBackground() {
		return background;
	}
	
	/*@Override public void setAppearance(WorldAppearance3D world) {
		this.world = world;
	}*/
	
	@Override public void preRender() {
		background.clear();
		WorldAppearance3D a = world;
		if (a != null)
			a.performPreDraw(background);
		background.paint(g3d, this);
	}

	@Override public void postRender() {
		super.postRender();
		hud.clear();
		WorldAppearance3D a = world;
		if (a != null)
			a.performPostDraw(hud);
		hud.paint(g3d, this);
	}
	
	/*============================================================
	Private Methods
	============================================================*/
	
	/** Returns true if the given property is set in the given properties. **/
	private static final boolean isSet(int properties, int property) {
		return ((properties & property) == property);
	}

	@Override
	public void preRender(WorldAppearance3D world) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void postRender(WorldAppearance3D world) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean setSymbiosis(WorldViewSymbiosis symb) {
		// TODO Auto-generated method stub
		return false;
	}
	
}
